package com.atguigu.tingshu.order.mapper;

import com.atguigu.tingshu.model.order.OrderInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {


    /**
     * 判断用户是否已经购买过该专辑
     * @param userId
     * @param itemId
     * @param itemType
     * @return
     */
    @Select("SELECT\n" +
            "COUNT(*)\n" +
            "FROM tingshu_order.order_info oi\n" +
            "INNER JOIN tingshu_order.order_detail od ON oi.id=od.order_id\n" +
            "WHERE oi.user_id=#{userId}\n" +
            " AND oi.order_status='0901' \n" +
            " AND oi.item_type=#{itemType}\n" +
            " AND od.item_id=#{itemId}")
    int getUserPaidAlbumTypeOrder(@Param("userId") Long userId, @Param("itemId") Long itemId,@Param("itemType") String itemType);

    @Select("SELECT\n" +
            "od.item_id\n" +
            "FROM tingshu_order.order_info oi\n" +
            "INNER JOIN tingshu_order.order_detail od ON oi.id=od.order_id\n" +
            "WHERE oi.user_id=#{userId}\n" +
            " AND oi.order_status='0901' \n" +
            " AND oi.item_type=#{itemType}")
    List<Long> getUserPaidTrackTypeOrder(@Param("userId") Long userId, @Param("itemType") String itemType);

    @Select("SELECT\n" +
            "COUNT(*)\n" +
            "FROM tingshu_order.order_info oi\n" +
            "INNER JOIN tingshu_order.order_detail od ON oi.id=od.order_id\n" +
            "WHERE oi.user_id=#{userId}\n" +
            " AND oi.order_status='0901' \n" +
            " AND oi.item_type=#{itemType}\n" +
            " AND od.item_id=#{itemId}")
    int getUserPaddingVipTypeOrder(@Param("userId") Long userId, @Param("itemId") Long itemId, @Param("itemType") String itemType);
}
